#include <queue>
#include <unordered_map>
typedef priority_queue<int, vector<int>, greater<int>> MINIMUM_HEAP;
class Solution 
{
public:
	bool isPossible(vector<int>& nums) 
	{
		unordered_map<int, MINIMUM_HEAP> mp;
		for (vector<int>::iterator iter = nums.begin(); iter != nums.end(); iter++)
		{
			if (mp.find(*iter) == mp.end())
			{
				mp[*iter] = MINIMUM_HEAP();              // 不存在以当前值结尾的最小堆，则新建一个
			}

			if (mp.find(*iter - 1) != mp.end())
			{
				int prevLength = mp[*iter - 1].top();    // 栈顶元素同时也是组成的字符串长度
				mp[*iter - 1].pop();
				if (mp[*iter - 1].empty())
				{
					mp.erase(*iter - 1);
				}
				mp[*iter].push(prevLength + 1);
			}
			else
			{
				mp[*iter].push(1);
			}
		}

		for (unordered_map<int, MINIMUM_HEAP>::iterator mp_iter = mp.begin(); mp_iter != mp.end(); mp_iter++)
		{
			MINIMUM_HEAP map_queue = mp_iter->second;
			if (map_queue.top() < 3)
			{
				return false;
			}
		}
		return true;

	}
};